# -*- encoding:utf-8 -*-
# !/usr/bin/env python
'''
    python-0824-04.py
    ======================
    @descript: 进程池  同步  异步
    @copyright:nnz
    @author:dln
    @date: 2021/8/23 20:02
    @version:v1.0
'''
import os
import time
from multiprocessing import Pool

from pip._vendor.certifi.__main__ import args


def f_01(pum):
    print('进程{}开始'.format(os.getpid()))
    for element in range(1,pum+1):
        print('进程输出的值为{}。'.format(element))
        time.sleep(1)
        pass
    print('进程{}结束'.format(os.getpid()))
    pass


#异步
if __name__=='__main__':
    v_pool =Pool(2)  # 创建进程池
    v_pool.apply_async(f_01,args=(10,))
    v_pool.apply_async(f_01, args=(4,))
    v_pool.apply_async(f_01, args=(7,))
    v_pool.apply_async(f_01, args=(16,))
    v_pool.apply_async(f_01, args=(8,))
    v_pool.close()
    v_pool.join()
    print('主进程结束')
    pass



# import os
# import time
# from multiprocessing import Pool
# from concurrent.futures import ProcessPoolExecutor
#
# def fun_01(pnum):
#     print('进程：{}start,……'.format(os.getpid()))
#     for element in range(1,pnum+1):
#         print('进程：输出的值为{}。'.format(element))
#         time.sleep(1)
#         pass
#     print('进程：{}end,……'.format(os.getpid()))
#     pass
#
# if __name__=='__main__':
#
#     v_pool=Pool(2)
#     v_pool.apply_async(fun_01,args=(3,))
#     v_pool.apply_async(fun_01,args=(4,))
#     v_pool.apply_async(fun_01,args=(5,))
#     v_pool.apply_async(fun_01,args=(6,))
#     v_pool.apply_async(fun_01,args=(7,))
#     v_pool.close()                 #  不是关闭进程池，后面不能添加内容到进程池里
#     v_pool.join()
#     print('主进程执行结束')
#     pass




